package cn.com.dcsgo.controller;

import cn.com.dcsgo.entity.User;
import cn.com.dcsgo.response.ResponseResult;
import cn.com.dcsgo.whitelist.annotation.WhiteList;
import org.springframework.web.bind.annotation.*;

/**
 * DemoController
 *
 * @author Dcsgo
 * @since 23/6/2025 上午 9:06
 */
@RestController
@RequestMapping("user")
public class UserController {
    @WhiteList("userId")
    @GetMapping("{userId}")
    public ResponseResult<User> get(@PathVariable Long userId) {
        ResponseResult<User> result = new ResponseResult<>();
        result.setData(new User(userId, "Dcsgo"));
        result.setCode(200);
        result.setMessage("success");
        return result;
    }

    @WhiteList(value = "userId", fallbackValue = "{\"code\":403,\"message\":\"该接口对您不可用\"}")
    @PutMapping
    public ResponseResult<User> update(@RequestBody User user) {
        ResponseResult<User> result = new ResponseResult<>();
        result.setData(user);
        result.setCode(200);
        result.setMessage("success");
        return result;
    }
}
